<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //    exec函数用于检索字符串中的正则表达式的匹配
        // 如果字符串中有匹配的值 则返回该匹配值 否则返回null
        var str = 'pink'
        var rg = /k/
        var rg1 = /o/
        var rg2 = /pink/
       console.log( rg.exec(str));//str里存在K ["k", index: 3, input: "pink", groups: undefined]
       console.log( rg1.exec(str));//null str里无o
       console.log( rg2.exec(str));//["pink", index: 0, input: "pink", groups: undefined]
    </script>
</body>

</html>